
package com.baijia.commons.config;

import java.util.Map;

import com.google.common.collect.Maps;


/**
 * @title PPWebContext
 * @desc 操作上下文信息 
 * @author caoliang
 * @date 2015年12月2日
 * @version 1.0
 */
public abstract class PPWebContext {
    
    protected static final ThreadLocal<Map<String, Object>> cache = new ThreadLocal<Map<String, Object>>() {
        @Override
        protected Map<String, Object> initialValue() {
            return Maps.newHashMap();
        }
    };
    
    protected abstract void init();
    
    protected static <T> void set(String key, T value){
        cache.get().put(key, value);
    }
    
    protected static Object get(String key){
        return cache.get().get(key);
    }
    
    @SuppressWarnings("unchecked")
    protected static <T> T get(String key, Class<T> clazz){
        return (T) cache.get().get(key);
    }
    
    public static void clear(){
        cache.remove();
    }
}
